package com.qq.xqj.mapper;

import com.qq.xqj.modle.Order_info;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
@Mapper
public interface Order_mapper {
    @Select("select *from order_info ")
    List<Order_info> queryAllOrder();

    @Delete("delete from order_info where order_id=#{orderId}")
    int deleteOrderById(String orderId);

    @Select("select *from order_info where  order_id=#{orderId}")
     Order_info queryOrderById(int orderId);

    @Update("update order_info SET brand=#{brand},type=#{type},color=#{color},selling_price=#{sellingPrice},salesman_name=#{salesmanName},salesman_id=#{salesmanId},payment=#{payment},royalty=#{royalty} WHERE order_id=#{orderId}")
    int updateOrderById(Order_info order_info);

    @Insert("insert into order_info values(null,#{brand},#{type},#{color},#{sellingPrice},#{salesmanName},#{salesmanId},#{sellingTime},#{payment},#{royalty})")
    int addOrder(Order_info order_info);

    @Select("<script> select * from order_info where"+
            "<if test='orderId != null'>order_id like concat('%',#{orderId},'%')" +
            "</if>"+
            "<if test='brand != null'> brand like concat('%',#{brand},'%')" +
            "</if>"+
            "<if test='type != null'> type like concat('%',#{type},'%')" +
            "</if>" +
            "<if test='color != null'> color like concat('%',#{color},'%')" +
            "</if>" +
            "<if test='salesmanName != null'> salesman_name like concat('%',#{salesmanName},'%')" +
            "</if>"+
            "<if test='sellingTime != null'> selling_time like concat('%',#{sellingTime},'%')" +
            "</if>"+
            "<if test='payment != null'> payment concat('%',#{payment},'%')" +
            "</if>"+
            "<if test='salesmanId != null'> salesman_id like concat('%',#{salesmanId},'%')" +
            "</if></script>")
    List<Order_info> queryOrderByKey(Order_info order_info);

}
